<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.lmpop.trade.ti_keyword.*"%>
<%@page import="com.lmpop.createIndex.search.*"%>
<%@page import="com.lmpop.frame.util.Config"%>
<%@page import="com.lmpop.frame.util.PageUtil"%>
<jsp:useBean id="pageUtil" class="com.lmpop.frame.util.PageUtil" scope="page" />
<%@page import="java.io.*"%>
<%!
	public String getDateStr(String in_date, String type) {
		if (in_date==null||in_date.equals(""))
			return "";
		if (in_date.length() >= 8) {
			String yeard = in_date.substring(0, 4);
			String monthd = in_date.substring(4, 6);
			String dayd = in_date.substring(6, 8);
			if (type.equals("")) {
				in_date = yeard + "-" + monthd + "-" + dayd;
			} else {
				in_date = monthd + "-" + dayd;
			}
		}
		return in_date;	
	}
%>	
<%!public String getPartLength(String key, int num) {
		if (key.equals(""))
			return "";
		if (key.length() > num)
			key = key.substring(0, num) + "...";
		return key;
	}

public String getBid_state(String auction_id){
			
			AuctionviewIndexFiles auctionviewIndex = new AuctionviewIndexFiles();
		    String bid_state = "";
			Hashtable map3 = new Hashtable();
			map3.put("auction_id",auction_id);
			try{
			List auctionviewList2 = auctionviewIndex.getAuctionviewList(map3);
					if(auctionviewList2!=null&&auctionviewList2.size()>0){
						for(int i=0;i<auctionviewList2.size();i++){
								Hashtable map = (Hashtable)auctionviewList2.get(i);
										if(map.get("bid_state")!=null){
												bid_state = map.get("bid_state").toString();
										}
										if(bid_state.equals("1")){
												return bid_state;		
										}
					    }
					}
			}catch(Exception e){
				e.printStackTrace();
			}
			return bid_state;		
		}
	%>

<%
	request.setCharacterEncoding("UTF-8");

	GoodsIndexFiles goodsIndex = new GoodsIndexFiles();
	CategoryIndexFiles catIndex = new CategoryIndexFiles();
	AttachIndexFiles attachIndex = new AttachIndexFiles();
	BrandIndexFiles brandIndex = new BrandIndexFiles();
	CategoryattrIndexFiles catattrIndex = new CategoryattrIndexFiles();

	Config configa = new Config();
	configa.init();
	String rootpath = configa.getString("rootpath");
	String goods_article_path = configa.getString("goods_article_path");
	String noimg_path = configa.getString("noimg_path");

	String keyword = "",cat_attr="", keyword_b = "", cat_id_para = "", brand_id_para = "",info_state="", orderby = "in_date", sort_type = "true";
	String start_price_para = "", end_price_para = "", attr_desc_para = "";
	if (request.getParameter("keyword") != null) {
		keyword_b = request.getParameter("q");
		keyword = java.net.URLDecoder.decode(keyword_b, "UTF-8");
	}
	if(!keyword.equals("")){
		Ti_keywordInfo keywordInfo = new Ti_keywordInfo();
		String key_type = "0";
		Hashtable keywordMap = new Hashtable();
		keywordMap.put("key_word",keyword);
	    keywordMap.put("key_type",key_type);
		keywordInfo.updateKeyWordNum(keywordMap);
	}
	if (request.getParameter("info_state") != null) {
		info_state = request.getParameter("info_state");
	}
	if (request.getParameter("cat_id_para") != null) {
		cat_id_para = request.getParameter("cat_id_para");
	}
	if (request.getParameter("cat_attr") != null) {
		cat_attr = request.getParameter("cat_attr");
		cat_id_para=cat_attr.substring(cat_attr.length()-16,cat_attr.length()-1);
	}
	
	if (request.getParameter("brand_id_para") != null) {
		brand_id_para = request.getParameter("brand_id_para");
	}

	Map comMap = new Hashtable();
	comMap.put("keyword", keyword);
	comMap.put("cat_id", cat_id_para);
	comMap.put("brand_id", brand_id_para);
	
	List goodsList = goodsIndex.getGoodsInfo(comMap);
	List catNumList=null;
	int cat_size =0;
	catNumList = goodsIndex.getGoodsCatListNum(cat_id_para,goodsList);
	if(catNumList!=null&catNumList.size()>0){
	 	cat_size=catNumList.size();
	 }else{
		cat_id_para="";
		brand_id_para="";
		start_price_para="";
		end_price_para="";
		catNumList = goodsIndex.getGoodsCatListNum(cat_id_para,goodsIndex.getGoodsInfo(new Hashtable()));
		if(catNumList!=null&catNumList.size()>0){
	 		cat_size=catNumList.size();
		 }
	 }
	

	String a_class=" background: none repeat scroll 0 0 #CC3300;color: #FFFFFF;";
	String page_class="background: none repeat scroll 0 0 #FF9933;border: 1px solid #FF9933;color: #FFFFFF;";
	
		Hashtable paraMap = new Hashtable();
	String _cat_id="",_good_name="";
	if(request.getParameter("good_name") != null && !request.getParameter("good_name").equals("")){
		_good_name = request.getParameter("good_name").toString();
		paraMap.put("good_name",_good_name);		
	}
	if(request.getParameter("cat_id") != null && !request.getParameter("cat_id").equals("")){
		_cat_id = request.getParameter("cat_id").toString();
		paraMap.put("cat_id",_cat_id);		
	}
	if (request.getParameter("cat_id_para") != null) {
		cat_id_para = request.getParameter("cat_id_para");
		paraMap.put("cat_id",cat_id_para);		
	}
	if (request.getParameter("cat_attr") != null) {
		cat_attr = request.getParameter("cat_attr");
		cat_id_para=cat_attr.substring(cat_attr.length()-16,cat_attr.length()-1);
		paraMap.put("cat_id",cat_id_para);		
	}
	AuctionIndexFiles auctionIndex = new AuctionIndexFiles();
	List auctionList = auctionIndex.getAuctionList(paraMap);
	int counter = 0;
	int limit = 10;
	
	int start = 0, end = limit;
	int startPage = 1;
	if (request.getParameter("start") != null
			&& !request.getParameter("start").equals("")) {
		start = Integer.parseInt(request.getParameter("start"));
	}
	if (start == 1 || start == 0) {
		start = 0;
		startPage = 1;
	} else {
		startPage = start;
		start = (start - 1) * limit;
	}
	end = start + limit;
	if(auctionList!=null&&auctionList.size()>0){
		paraMap = (Hashtable)auctionList.get(start);
		if(paraMap!=null&&!(paraMap.get("auction_id").toString()).equals("0")){
			counter = auctionList.size();
		}
	}
	if (end > counter) {
		end = counter;
		start = (((counter - 1) / limit + 1) - 1) * limit;
	}
	String com_page="shop_auction.html";
	String url = "shop_auction.html?cat_id="+_cat_id;
	String pageString = pageUtil.getPageString(url,counter,limit,startPage,request);
	String cat_name_para = catIndex.getCatNameById(cat_id_para);
	String brand_name_para = brandIndex.getBrandNameById(brand_id_para);
	
	List sonCatNumList=null;
%>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>雷鸣商城-拍卖列表页</title>
<link href="/templets/html/shop/css/style.css" rel="stylesheet" type="text/css" />
<link href="/templets/html/shop/css/prolistnew.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/templets/html/shop/js/jquery_002.js"></script>
<script type="text/javascript" src="/templets/html/shop/js/prolistnew.js"></script>
	<script type='text/javascript' src='/dwr/engine.js'></script>
		<script type='text/javascript' src='/dwr/util.js'></script>
		<script type='text/javascript' src='/dwr/interface/Ti_subscribeInfo.js'></script> 
		<script type='text/javascript' src='/templets/html/shop/js/_shop.js'></script>
</head>
<body>
<script> 
  document.write("<s" + "cript type='text/javascript' src='/templets/html/shop/top.jsp?" + Math.random() + "'></scr" + "ipt>");
</script>
<div id="contaner">
  <div class="ShoesList">
    <div class="areaSide">
      <div class="sorttitle">拍卖商品分类</div>
		<div class="sort">
<%
	
	if (catNumList != null && catNumList.size() > 0) {
					Hashtable nMap = new Hashtable();
						for (int i = 0; i < catNumList.size(); i++) {
							nMap = (Hashtable) catNumList.get(i);
							String cat_id = "", cat_name = "", cat_num = "";
							if (nMap.get("cat_id") != null){
								cat_id = nMap.get("cat_id").toString();
							}
							if (nMap.get("cat_name") != null)
								cat_name = nMap.get("cat_name").toString();
							if (nMap.get("cat_num") != null)
								cat_num = nMap.get("cat_num").toString();
							
				%>
				 <%
					        	if(cat_id_para.equals("cat_id")){%>
					        		<h2><a href="javascript:updateCatIdBySearch('cat_id_para','<%=cat_id %>');" class="open"></a><%=cat_name%></h2>
									<ul style='display: block;'>
								<%}else if(i==0){%>
									<h2><a href="javascript:updateCatIdBySearch('cat_id_para','<%=cat_id %>');" class="open"></a><%=cat_name%></h2>
					        		<ul style='display: block;'>
					        	<%}else{%>
					        		<h2><a href="javascript:updateCatIdBySearch('cat_id_para','<%=cat_id %>');" ></a><%=cat_name%></h2>
					        		<ul class="hide">
					        	
					        	<%}
					         %>
					          <li class="allshoes current"><strong>所有<a href="javascript:updateCatIdBySearch('cat_id_para','<%=cat_id %>');"><%=cat_name%></a></strong></li>

				 	<%
					       		sonCatNumList=catIndex.getCategoryByUpCatId(cat_id,"2");
					       		Map mMap=null;
					       		if(sonCatNumList!=null&&sonCatNumList.size()>0){
					       			String son_cat_id="",son_cat_name="";
					       			for(int j=0;j<sonCatNumList.size();j++){
					       				mMap = (Hashtable) sonCatNumList.get(j);
					       				if (mMap.get("cat_id") != null){
					       					son_cat_id = mMap.get("cat_id").toString();
					       				}
											
										if (mMap.get("cat_name") != null)
											son_cat_name = mMap.get("cat_name").toString();%>
					       				<li><a class="type" href="javascript:updateCatIdBySearch('cat_id_para','<%=son_cat_id %>');"><%=son_cat_name %></a></li>
					       			<%}
					       		}
					       	 %> 
					        </ul>
							<%
								}
							}else{%>
								<ul style='display: block;'>
									<li>暂无拍卖分类</li>
								</ul>	
							<%}
							%>
      </div>
      <div id="RecommendedResults"></div>
    </div>
    <div class="areaShoesList">
      <div class="location">
        <div><a href="<%=com_page %>">拍卖商品分类</a> &gt;
        <%
        	if(cat_name_para==null||"".equals(cat_name_para))
        		out.print("所有商品");
        	else{%>
        	  <a href="#" class="defaultColor">
	          	<h1><%=cat_name_para %></h1>
	          </a>
        	<%}
         %>
       
        </div>
        (共找到<b><%=counter%></b>款) </div>
      <div class="shoesnav">       
        <a name="aa"></a> </div>
      <div id="mainshow" style="width:792px; overflow:hidden;" class="mainshow">
        <ul class="blickShoesList" style="width:792px; overflow:hidden;">
        
        	<%
Hashtable map = new Hashtable();
String auction_id = "",auction_name="", bid_state="",good_id = "",good_name = "",start_date="",end_date="", start_price = "", a_price = "",file_path="";
	if(auctionList!=null&&auctionList.size()>0){
		end = end>auctionList.size()?auctionList.size():end;
			for(int i=start;i<end;i++){
					map = (Hashtable)auctionList.get(i);
					if(map!=null&&!(map.get("auction_id").toString()).equals("0")){
						if (map.get("auction_id") != null) {
							auction_id = map.get("auction_id").toString();
						}
						if (map.get("auction_name") != null) {
							auction_name = map.get("auction_name").toString();
						}
						if (map.get("good_id") != null) {
							good_id = map.get("good_id").toString();
						}
						if (map.get("goods_name") != null) {
							good_name = map.get("goods_name").toString();
							if(good_name.length()>25)
								good_name=good_name.substring(0,25);
						}
						if (map.get("start_date") != null) {
							start_date = map.get("start_date").toString();
							start_date = getDateStr(start_date,"");
						}
						if (map.get("end_date") != null) {
							end_date = map.get("end_date").toString();
							end_date = getDateStr(end_date,"");
						}
						if (map.get("start_price") != null) {
							start_price = map.get("start_price").toString();
						}
						if (map.get("file_path") != null) {
							file_path = map.get("file_path").toString();
						}
					
			
			
				   long start_date_int = 0,end_date_int=0,now_date_int=0;
			
				    java.text.DateFormat df2 = new java.text.SimpleDateFormat("yyyy-MM-dd");
				    if(start_date!=null&&!"".equals(start_date)){
				    	start_date_int = df2.parse(start_date).getTime();
			    		end_date_int = df2.parse(end_date).getTime();
				    }
			    	
			    	now_date_int = new java.util.Date().getTime();
			    	bid_state =  getBid_state(auction_id);
			    	
			    	//out.println(start_date_int + "=" +end_date_int + "=" + now_date_int);
			    	
			    	String auction_state="";
			    	
			    		if(now_date_int >= start_date_int && now_date_int <= end_date_int){
							auction_state="<font color='red'>该拍卖活动正在进行中</font>";
						}
						if(now_date_int < start_date_int){
							auction_state="该拍卖活动还没开始";
						}
						if(now_date_int > end_date_int){
							auction_state="该拍卖活动已经结束";
						}
						
						if(bid_state.equals("1")){
							auction_state="因有人中标而结束";
						}	
			%>


				 <li>
		           
		            <a href="/shop_auction_view.html?auction_id=<%=auction_id%>" class="img">
		             <img  src="<%=file_path%>" class="goodThumb" ></a>
		            <p> <%=auction_state%><br>
		               起拍价：<del class="gray">￥<%=start_price%></del> </p>
		            <p class="name"><a href="/shop_auction_view.html?auction_id=<%=auction_id%>" ><%=good_name %></a></p>
		          </li>
				
				<%
				}
						}
					}
	%>


        </ul>
        <div class="clear"></div>
        <div class="page_list" style="border:0">
      <div class="page">
      <%=pageString %>
      </div>
    </div>
      </div>
    </div>
    <div class="clear"></div>
  </div>
  			<form action="<%=com_page%>" method="get" name="tongSearchForm">
					<input type="hidden" name="q" id="new_q" value="<%=keyword_b%>" />
					<input type="hidden" name="attr_desc_para" id="attr_desc_para"
						value="" />
					<input type="hidden" name="orderby_para" id="orderby_para"
						value="<%=orderby%>" />
					<input type="hidden" name="sort_type" id="sort_type"
						value="<%=sort_type%>" />
					<input type="hidden" name="info_state" id="info_state"
						value="<%=info_state %>" />
					<input type="hidden" name="cat_id_para" id="cat_id_para"
						value="<%=cat_id_para%>" />
					<input type="hidden" name="brand_id_para" id="brand_id_para"
						value="<%=brand_id_para%>" />
					<input type="hidden" name="start_price_para" id="start_price_para"
						value="<%=start_price_para%>" />
					<input type="hidden" name="end_price_para" id="end_price_para"
						value="<%=end_price_para%>" />
					<input type="hidden" name="start" value="<%=startPage%>" />
					<input type="hidden" name="listOrImg" id="listOrImg"
						value="" />
				</form>
			<script>
				function tongyiSearch(orderby,sort_type){
					document.getElementById('orderby_para').value = orderby;
					document.getElementById('sort_type').value = sort_type;
					document.tongSearchForm.submit();
				}
				function state_codeSearch(val){
					document.getElementById('info_state').value = val;
					document.tongSearchForm.submit();
				}
				function updateCatIdBySearch(param_id,param_value){
					document.getElementById(param_id).value = param_value;
					document.tongSearchForm.submit();
				}
				function updateCatIdBySearchSize(param_id,param_value,cat_size){
					document.getElementById(param_id).value = param_value;
					if(cat_size <= 0){
					document.getElementById('new_q').value = '';
					}
					document.tongSearchForm.submit();
				}	
				function dealCatattr(param_id,param_value){
					document.getElementById(param_id).value = document.getElementById(param_id).value + param_value;
					document.tongSearchForm.submit();
				}
				function setSearchPrice(start_price,end_price){
					document.getElementById('start_price_para').value = start_price;
					document.getElementById('end_price_para').value = end_price;
					document.tongSearchForm.submit();
				}
				function replaceSpaceAttr(attr_desc){
					document.getElementById('attr_desc_para').value = document.getElementById('attr_desc_para').value.replace(attr_desc,'');
					document.tongSearchForm.submit();
				}
				function showList(val)
				{
				  document.getElementById('listOrImg').value = val;
				  document.tongSearchForm.submit();
				}
			</script>
	<jsp:include page="/templets/html/shop/footer.jsp"/>
	</body>
</html>

